$(function(){
	
		var $pg_loader	=	$('#pg_loader-20');
		var $bgImage	= 	$('.container_all img:first');
		var $theme = $('.container_all').find('img.pg_bg').length;
		
		
		//$("body").css("display", "none");
		
		//page redirection 	
		$(".content-20").css("display", "none");
		$("#popdiv").hide();
		//$logoelem.fadeIn();
		$(".content-20").fadeIn(1000);	
		$("a.plinks").click(function(event){
			event.preventDefault();
			linkLocation = this.href;
			$(".content-20").fadeOut(600, redirectPage);		
		});
		function redirectPage() {
			window.location = linkLocation;
		}
		
			
		
		cssprImgs();
		function cssprImgs(){
			//added for css images
			var loadedImgs = $.preloadCssImages({statusTextEl: '#textStatus', statusBarEl: '#status'});
				for(var i = 0; i<loadedImgs.length; i++){
						$('#loadedImgs').append('<li><img src=\"'+loadedImgs[i].src+'\" />: '+loadedImgs[i].src+'</li>');
						//alert(loadedImgs.length);
					}
					
					setTimeout(function(){
							themeCheck();	
							},1000);
			}
		function themeCheck(){
		if($theme > 0 ){
		
					$('<img>').load(function(){
						//$pg_loader.hide();
						setTimeout(function(){
							themeAvailable();	
							//alert('image check');
							},1000);
						}).attr('src',$bgImage.attr('src'));
						
					} else if($theme == 0) {
							//$pg_loader.hide();
							setTimeout(function(){
							noTheme();	
							//alert('no theme');
							},100);
						}
		
		}
		function themeAvailable(){
			//$("body").fadeIn();
			hideCur();
			setTimeout(function(){
					$pg_loader.hide();
						themeBg();
						},400);
			}
		function noTheme(){
			//$("body").fadeIn();
			hideCur();
			setTimeout(function(){
					$pg_loader.hide();
						topstrip();
						},300);
			}
		
		function themeBg(){
		$(".container_all img:first").animate({ width:'980px', height:'920px', left:'0px', right:'0px', top:'0px', opacity:'0.6'},600,'easeOutCubic', null);
		$(".pg_overlay_20").animate({left:"0px",opacity:1},1200,'easeOutQuart',null);
		setTimeout(function(){
					topstrip();
					},100);		
		}	
		
			
			
			
						function topstrip() {
			$(".topstrip_20").animate({opacity:1},500,'easeOutQuad',null);
			setTimeout(function(){
						bottomstrip();
						},300);
			}
		
								function bottomstrip() {
			$(".bottomstrip-20").animate({opacity:1},500,'easeOutQuad',null);
			setTimeout(function(){
						logoimg();
						},300);
			}
			function logoimg() {
			$(".logoholder-20 img").animate({opacity:1},500,'easeOutQuad',null);
			setTimeout(function(){
						logoAnim();
						},300);
			}
			
			function logoAnim() {
				$("#logo-in-020").animate({opacity:1},200,'easeOutQuad',null);
				$("#logo-in-020 h2").animate({opacity:1},300,'easeOutQuad',null);
				$("#logo-in-020 h1").animate({opacity:1},300,'easeOutQuad',null);				
				setTimeout(function(){
							squarbox_red();
							},300);
				}
			function squarbox_red() {
			$(".squarbox_red_20").animate({opacity:0.92},300,'easeOutQuad',null);
			setTimeout(function(){
						squarbox_black();
						},100);
			}	
			function squarbox_black() {
			$(".squarbox_black_20").animate({opacity:1},300,'easeOutQuad',null);
			setTimeout(function(){
						menu_line();
						},100);
			}	
			function menu_line() {
			$(".menu_line").animate({opacity:1},500,'easeOutQuad',null);
			setTimeout(function(){
						navin();
						},100);
			}	
			function navin(){
			$("ul#nav-in-020").animate({opacity:1},800,'easeOutBack',null);
				setTimeout(function(){
							homeicon();
							},200);
				}
			function homeicon() {
				$(".homeicon_20").animate({opacity:1},300,'easeOutQuad',null);
				setTimeout(function(){
							socialnetwork();
							},100);
				}	
			function socialnetwork() {
				$(".socialnetwork-20").animate({opacity:1},300,'easeOutQuad',null);
				setTimeout(function(){
							socialnetwork2();
							},200);
				}
			function socialnetwork2() {
				$(".socialnetwork2-20").animate({opacity:1},300,'easeOutQuad',null);
				setTimeout(function(){
							content();
							},200);
				}
			function content() {
				$(".content-20").animate({opacity:1},600,'easeOutQuad',null);
				//$("#scrollBox_20").css('display','none');
				setTimeout(function(){
							//$("#scrollBox_20").niceScroll({cursorborder:"",cursorcolor:"#5C90B1",boxzoom:true});
							//$("#scrollBox_20").fadeIn();
							contactus();
							},800);
				}
				
			function contactus(){
				$(".contactus-20").animate({opacity:1},600,'easeOutBack',null);
				setTimeout(function(){
				//$("#scrollBox_20").niceScroll({cursorborder:"",cursorcolor:"#5C90B1",boxzoom:false});
				$("#scrollBox_20").jScrollPane({
						showArrows:true,
						maintainPosition: false,
						autoReinitialise: true
					});
							store();
							},30);
				}
			function store(){
				$(".store-20").animate({opacity:1},600,'easeOutBack',null);
				setTimeout(function(){
							mediaplayer();
							},30);
				}
			function mediaplayer(){
				$(".mediaplayer-20").animate({opacity:1},600,'easeOutBack',null);
				setTimeout(function(){
							sitegallery();
							},30);
				}
			function sitegallery(){
				$(".sitegallery-20").animate({opacity:1},600,'easeOutBack',null);
				setTimeout(function(){
							snetworks();
							},800);
				}
			function snetworks(){
				$(".snetworks").animate({opacity:1},800,'easeOutBack',null);
				setTimeout(function(){
							bottomtext();
							},50);
				}
			function bottomtext(){
				$(".bottomtext-20").animate({opacity:1},800,'easeOutBack',null);
				setTimeout(function(){
							allHovers();
							copyTxt();
							},300);
				}

		//copyTxt animation					
			function copyTxt() {
			$(".copyrightTxt_styl20").animate({opacity:1},1400,'easeOutQuad',null);
			}	
			
		function allHovers(){
		//$("body").niceScroll();	
		showCur();
		//icons hover animations
		var $iconbtnhover = $('.sitegallery-20, .mediaplayer-20, .store-20, .contactus-20');
		
		$iconbtnhover.hover(function(){
				$(this).stop().animate({marginTop:'5px' },600,'easeOutElastic',null);
				},function(){
				$(this).stop().animate({marginTop:'0px'},600,'easeOutElastic',null);
			});
			
		var $sublinks =  $('ul.submenu-20').children('li').not('li.current,li.imgholder-20');
	
			$sublinks.hover(function(){
				$(this).find('a').stop().animate({marginLeft:'0px',color:'#fff', backgroundColor:'#FFD200'},400,'easeOutQuad',null);
				},
			function(){
				$(this).find('a').stop().animate({marginLeft:'0px',color:'#fff', backgroundColor:'#000000'},400,'easeOutQuad',null);
		 	});
		
		//social network icons hover animations	
		var $snetworkbtns =  $('.snetworks img, .socialnetwork-20 img, .socialnetwork2-20 img, .homeicon_20 img');
		
			$snetworkbtns.hover(function(){
				$(this).stop().animate({marginTop:'-6px'},600,'easeOutElastic');
				},function(){
				$(this).stop().animate({marginTop:'0px'},400,'easeOutBounce');
			});
		
		//sub-menu btn hover animations	
		var $sbmenubtns =  $('ul#nav-in-020 li').not('li.current');
	
			$sbmenubtns.hover(function(){
				$(this).stop().animate({left:'0px'},1000,'easeOutElastic');
				$(this).find('span').addClass('ovr');
				},
			function(){
				$(this).stop().animate({left:'0px'},1000,'easeOutElastic');
				$(this).find('span').removeClass('ovr');
		 	});
	
		//image hover
		var $imgov = $('.imgholder-20');
			
			$imgov.hover(function(){
				$(this).stop().animate({backgroundColor:'#FFD200'},500,'easeOutQuad');
			},
			function(){	
				$(this).stop().animate({backgroundColor:'#DCDCDC'},300,'easeOutQuad');
			});
			
		}
		/*cursor wait*/
		function hideCur(){
				$('body').css('cursor','wait');
		}
		function showCur(){
				$('body').css('cursor','default');
		}
		
		
		resizepageimg();
		function resizepageimg(){
			$(".imgholder-20 img").each(function(){
		
		
				var  tmpimg = $(this);
				src= $(this).attr("src");
				var img = new Image(); 
				img.src = src; 
				img.onload = function() { 
						
						width  =  this.width;
						height = this.height;
						
						if(width<height){
							tmpimg.addClass("heightImg");
						}else{
							
						}
						
				} 
				
			});	
		
		  return true;	
			
		}
		
		
	
});

